package com.yzf.demo.demo.Thread.lock;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

/**
 * Created by 于占峰 on 2020/4/4/004.
 */
public class ConditionDemoNotify extends Thread {
    //使用concurrent中的锁
    private Lock lock;

    private Condition condition;

    public ConditionDemoNotify(Lock lock, Condition condition) {
        this.lock = lock;
        this.condition = condition;
    }

    @Override
    public void run() {
        try {
            System.out.println("begin - Condition--notify");
            lock.lock();//加锁
            condition.signal();//唤醒线程
            System.out.println("end - Condition--notify");
        } finally {
            lock.unlock();//释放锁
        }

    }
}
